import pandas as pd
import json
import demjson
import pymysql

Host = '127.0.0.1'
User = 'root'
Password = ''
dbname='szhouse'

db = pymysql.connect(Host,User,Password,dbname,charset="utf8")
cursor = db.cursor()

file = "/Users/super/PycharmProjects/ShenzhenRealestate/HouseData/House.json"
with open(file,'r') as f :
    data = f.read()

data = data.replace('\n','')

t = data.split('{')

jtt=[]
for i in range(len(t)):
    if 'ljid' in t[i]:
        tt = '{' + t[i]
        jtt.append(tt)

for i in range(len(jtt)):
    l = json.loads(jtt[i])
    print(l['ljid'])

    sql="INSERT INTO lianjiav4 ( `ljid`, `jg`, `xqmc`, `szqy`, `jd`, `hx`, `jzmj`, `tnmj`, `fwcx`, `jzjg`, `hxjg`, `zxqk`, `thbl`, `dt`, `cqnx`, `gpsj`, `jyqs`, `scjysj`, `fwyt`, `fwnx`, `cqss`, `dyxx`) VALUES(%(ljid)s,%(jg)s,%(xqmc)s,%(szqy)s,%(jd)s,%(hx)s,%(jzmj)s,%(tnmj)s,%(fwcx)s,%(jzjg)s,%(hxjg)s,%(zxqk)s,%(thbl)s,%(dt)s,%(cqnx)s,%(gpsj)s,%(jyqs)s,%(scjysj)s,%(fwyt)s,%(fwnx)s,%(cqss)s,%(dyxx)s)"
    value ={
    'ljid':l['ljid'],
    'jg':l['jg'],
    'xqmc':l['xqmc'],
    'szqy':l['szqy'],
    'jd':l['jd'],
    'hx':l['hx'],
    'jzmj':l['jzmj'],
    'tnmj':l['tnmj'],
    'fwcx':l['fwcx'],
    'jzjg':l['jzjg'],
    'hxjg':l['hxjg'],
    'zxqk':l['zxqk'],
    'thbl':l['thbl'],
    'dt':l['dt'],
    'cqnx':l['cqnx'],
    'gpsj':l['gpsj'],
    'jyqs':l['jyqs'],
    'scjysj':l['scjysj'],
    'fwyt':l['fwyt'],
    'fwnx':l['fwnx'],
    'cqss':l['cqss'],
    'dyxx':l['dyxx']
}
    cursor.execute(sql, value)
    db.commit()